home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / tlx_sq21.zip / UPDOWNF.SLT < prev    next >
Text File  |  1992-03-20  |  8KB  |  233 lines

  1. //-----------------------------------------------------------
  2. // UpDownF.SL?  Telix script to upload or download a file. Uses
  3. //              external or internal protocol.
  4. //
  5. // Please look at the comments through the whole file, and modify to
  6. // suit your needs, BEFORE you use it. Then recompile with CS UpDownF.
  7. //-----------------------------------------------------------
  8.  
  9. // If you have suggestions for improving this script, please suggest
  10. // improvements to me via old-fashioned snail-mail to:
  11.  
  12. // Author:  Inge Vabekk
  13. //          Hamangskogen 108
  14. //          N-1300 SANDVIKA
  15. //          NORWAY
  16. //          tel. (472) 546 396
  17.  
  18.                              // For the Global storage:
  19. str global   []="GLOBAL"     // Global script.
  20.    ,crdir    []="CRDIR"      // Create directory program
  21.    ,Cprot    []="CPROT"      // Current protocol.
  22.    ,xprot    []="XPROT0"     // External protocol.
  23.    ,xprog    []="XPROG0"     // External protocol program (variable)
  24.    ,xpram    []="XPRAM0"     // Parameters for external
  25.                              // protocol program
  26.    ,xrecv    []="XRECV0"     // Receive parameters (variable)
  27.    ,xxmit    []="XXMIT0"     // Send parameters (variable)
  28.    ,params [12]              // Receive/transmit parameters (string)
  29.    ,program[12]              // External protocol program (name)
  30.    ,runstr [80]              // Run string for protocol program.
  31.    ,Downdir[64]              // Save download dir.
  32.    ,myprot  [2]              // My protocol
  33.    ;
  34. int UseExternal              // TRUE for external protocol program.
  35.    ,protocol
  36.    ;
  37.  
  38. //-----------------------------------------------------------
  39. // GetFile script is entered here.
  40. //-----------------------------------------------------------
  41.  
  42. // Parameters: Put=1 for SEND, Put=0 for RECEIVE.
  43.  
  44. main(int Put, str filedir, str filename)
  45. {
  46. int i, m, s, start_time;
  47.  
  48. // Check if online.
  49. //-----------------------------------------------------------
  50.  
  51.   if (!carrier())
  52.   { failtune();                          // No, failure.
  53.     status_wind ("T²: YOU CAN ONLY DOWNLOAD IF YOU'RE ONLINE!",20);
  54.     return(-1);
  55.   }
  56.   run (crdir,filedir,0);          // Create file dir. if it doesn't exist.
  57.  
  58.   read (cprot,myprot);            // Get protocol.
  59.   protocol = subchr (myprot,0);   // Must be INT.
  60.  
  61. // Check if external protocol should be used.
  62. //-----------------------------------------------------------
  63.  
  64.   UseExternal = 0;                     // = 1 for external protocol.
  65.   for (i='0'; i<='9'; ++i)
  66.   { setchr (xprot,5,i);
  67.     if (read (xprot,runstr) > 0)
  68.     { if (runstr==myprot)
  69.       { setchr (xprog,5,i);
  70.         if (read (xprog,program) > 0)  // External program defined?
  71.         { UseExternal = 1;             // = 1 for external protocol.
  72.           break;                       // Break out.
  73.         }
  74.       }
  75.     }
  76.   }
  77.   if (UseExternal)
  78.   { setchr (xpram,5,i);
  79.     if (read (xpram,runstr) <= 0)      // Parameters defined?
  80.     { runstr = "T²: Run parameters (";     // NO!
  81.       strcat (runstr,xpram);
  82.       strcat (runstr,") for ");
  83.       strcat (runstr,program);
  84.       strcat (" are not defined!");
  85.       status_wind (runstr,20);
  86.       failtune();
  87.       UseExternal = 0;                 // = 1 for external protocol.
  88.     }
  89.   }
  90.   if (UseExternal && Put)              // Send using external protocol?
  91.   { setchr (xxmit,5,i);
  92.     if (read (xxmit,params) <= 0)      // Send parameters defined?
  93.     { runstr = "T²: Send parameters (";
  94.       strcat (runstr,xxmit);
  95.       strcat (runstr,") for ");
  96.       strcat (runstr,program);
  97.       strcat (" are not defined!");
  98.       status_wind (runstr,20);
  99.       failtune();
  100.       UseExternal = 0;                 // = 1 for external protocol.
  101.     }
  102.   }
  103.   else if (UseExternal)
  104.   { setchr (xrecv,5,i);
  105.     if (read (xrecv,params) <= 0)      // Receive parameters defined?
  106.     { runstr = "T²: Receive parameters (";
  107.       strcat (runstr,xrecv);
  108.       strcat (runstr,") for ");
  109.       strcat (runstr,program);
  110.       strcat (" are not defined!");
  111.       status_wind (runstr,20);
  112.       failtune();
  113.       UseExternal = 0;                   // = 1 for external protocol.
  114.     }
  115.   }
  116.  
  117.   if (!Put && Protocol=='Z') 
  118.     waitfor ("**",1);                 // Check Zmodem transfer.
  119.   terminal();                          // Update screen.
  120.   start_time = curtime();              // start transfer time.
  121.  
  122.   if (UseExternal)
  123.   { strcat (runstr," ");               // Complete run string.
  124.     strcat (runstr,params);
  125.     strcat (runstr," ");
  126.     strcat (runstr,filename);
  127.     newdir (filedir);                  // Must be in the download dir!
  128.     i = run (program,runstr,0);        // Use external program.
  129.     newdir (_telix_dir);               // Return to TELIX directory!
  130.   }
  131.   else if (Put)                        // Send file:
  132.   { Downdir = _up_dir;                 // Save upload dir.
  133.     _up_dir = filedir;
  134.     i = send (protocol,filename);      // Use defined protocol!
  135.     i = i < 0;                         // Error if negative.
  136.     _up_dir = downdir;                 // Restore upload directory.
  137.   }
  138.   else                                 // Receive file:
  139.   { Downdir = _down_dir;               // Save download dir.
  140.     _down_dir = filedir;
  141.     i = receive (protocol,filename);   // Use defined protocol!
  142.     i = i < 0;                         // Error if negative.
  143.     _down_dir = downdir;               // Restore download directory.
  144.   }
  145.  
  146.   if (i)                               // Good transfer?
  147.     failtune();                        // No, bad.
  148.   else
  149.   { s=start_time = curtime()-start_time; // Calculate no. of seconds.
  150.     goodtune();
  151.     m = s/60;
  152.     s = s - m*60;
  153.     prints ("");
  154.     printsc ("T²: Transfer time: ");
  155.     if (m > 0)
  156.     { printn (m);
  157.       printsc (" minute");
  158.       if (m > 1) printsc ("s");
  159.       printsc (", ");
  160.     }
  161.     printn (s);
  162.     printsc (" second");
  163.     if (s > 1) printsc ("s");
  164.     runstr = filedir;                  // Find filename.
  165.     strcat (runstr,filename);
  166.     if ((m=filesize(runstr)) > 0)      // Found?
  167.     { printsc (", transfer speed: ");  // So print CPS rate.
  168.       printn (m/start_time);
  169.       printsc (" bytes per second");
  170.     }
  171.     prints (".");
  172.   }
  173.   return (i);
  174. }
  175.  
  176. //-----------------------------------------------------------
  177. // Play good tune.
  178. //-----------------------------------------------------------
  179.  
  180. goodtune()
  181. {
  182. int n;
  183.   for (n=40; n< 200; n = 144*n/100)
  184.   { tone(n*10,6);                        // Good tone!
  185.     terminal();                          // Process text!
  186.   }
  187. }
  188.  
  189. //-----------------------------------------------------------
  190. // Play fail tune.
  191. //-----------------------------------------------------------
  192.  
  193. failtune()
  194. {
  195. int n;
  196.   for (n=120; n > 30; n = 100*n/105)
  197.   { tone(n*10,6);                        // Fail tone!!
  198.     terminal();                          // Process text!
  199.   }
  200. }
  201.  
  202. //-----------------------------------------------------------
  203. // Read a global variable.
  204. //-----------------------------------------------------------
  205.  
  206. read (str name, str varname)
  207. {
  208.   return (call (global,"R",name,varname));
  209. }
  210.  
  211. //-----------------------------------------------------------
  212. // Write a global variable.
  213. //-----------------------------------------------------------
  214.  
  215. write(str name, str varname)
  216. {
  217.   return (call (global,"W",name,varname));
  218. }
  219.  
  220. //-----------------------------------------------------------
  221. // Strip trailing spaces from string.
  222. //-----------------------------------------------------------
  223.  
  224. strip (str string)                       // Strip strailing spaces,
  225. {                                        // return length.
  226. int l;
  227.   for (l=strlen(string); l>=0; --l)
  228.   { if (subchr(string,l) > ' ') return (++l);
  229.     setchr(string,l,0);
  230.   }
  231.   return (0);
  232. }
  233.